<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>数组算法-遍历</title>
</head>
<body>
<script>
console.log('----------------------forEach----------------------');
const arr01 = [5, 3, 9, 4, 8];
//共3个参数
const res01 = arr01.forEach((item, index, arr) => {
	if(index == 2) {
		return false;// 不会中断后续的遍历
	}
	console.log('forEach:', item, index);
});
console.log('res01:', res01);//undefined
</script>
<script>
console.log('----------------------map----------------------');
const arr02 = [5, 3, 9, 4, 8];
// every,该数组是否已全部遍历,若每他遍历的元素都return true,则接收值的值为true
const res02 = arr02.map((item, index, arr) => {
	if(index == 2) {
		return false;// 停止遍历
	}
	console.log('map:', item, index);
	return true;//继续遍历
});
console.log('res02:', res02);//[true, true, false, true, true]
</script>
</body>
</html>